package com.restaurant.controller;

import com.restaurant.bean.ResponseResult;
import com.restaurant.bean.User;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("user")
public class UserController {


    @GetMapping
    public ResponseResult query(@RequestParam(required = true) User user) {
        if (Objects.isNull(user)) {
            return ResponseResult.error("用户不存在！");
        } else {
            return ResponseResult.success(user);
        }
    }

    @PostMapping("login")
    public ResponseResult login(@RequestBody(required = true) User user) {
        if (Objects.isNull(user)) {
            return ResponseResult.error("用户名或密码错误！");
        } else {
            return ResponseResult.success(user);
        }
    }


    @PostMapping
    public ResponseResult save(@RequestBody User user) {
        if (Objects.isNull(user)) {
            return ResponseResult.error("用户更新失败！");
        } else {
            return ResponseResult.success(user);
        }
    }

    @PostMapping("forget-password")
    public ResponseResult forgetPassword(@RequestBody(required = true) User user) {
        if (!Objects.isNull(user)) {
            return ResponseResult.success(user);
        } else {
            return ResponseResult.error("个人信息不正确！");
        }
    }

}
